package com.fjrcloud.controller;

import com.fjrcloud.entity.*;
import com.fjrcloud.exception.BusinessException;
import com.fjrcloud.service.HousingStructureService;
import com.fjrcloud.utils.StatusUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by shengjian.lin on 17-1-18.
 */
@Controller
@RequestMapping("api/housing/structure")
public class HousingStructureController {

    @Autowired
    private HousingStructureService service;

    @RequestMapping("save")
    @ResponseBody
    public ResponseBean save(HousingStructure structure){

        return ResponseFactory.getResponseBean(StatusUtils.Success,service.saveStructure(structure));
    }
    @RequestMapping("get")
    @ResponseBody
    public ResponseBean get(Integer id){
        return ResponseFactory.getResponseBean(StatusUtils.Success,service.getStructure(id));
    }
    @RequestMapping("del")
    @ResponseBody
    public ResponseBean del(Integer id){
        service.delStructure(id);
        return ResponseFactory.getResponseBean(StatusUtils.Success);
    }
    @RequestMapping("find")
    @ResponseBody
    public ResponseBean find(Integer pageNum, Integer pageSize){
        return ResponseFactory.getResponseBean(StatusUtils.Success,service.listStructure(pageNum,pageSize));
    }

    @RequestMapping("level/save")
    @ResponseBody
    public ResponseBean saveStructureLevel(Integer structureId, HousingStructureLevel level) throws BusinessException {

        return ResponseFactory.getResponseBean(StatusUtils.Success,service.saveStructureLevel(structureId,level));
    }
    @RequestMapping("level/get")
    @ResponseBody
    public ResponseBean getStructureLevel(Integer id){
        return ResponseFactory.getResponseBean(StatusUtils.Success,service.getStructureLevel(id));
    }
    @RequestMapping("level/del")
    @ResponseBody
    public ResponseBean delStructureLevel(Integer id){
        service.delStructureLevel(id);
        return ResponseFactory.getResponseBean(StatusUtils.Success);
    }
    @RequestMapping("level/find")
    @ResponseBody
    public ResponseBean findStructureLevel(Integer structureId,Integer pageNum, Integer pageSize) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success,service.listStructureLevel(structureId,pageNum,pageSize));
    }

    @RequestMapping("intoNew/save")
    @ResponseBody
    public ResponseBean saveStructureIntoNew(HousingStructureIntoNew intoNew) throws BusinessException {

        return ResponseFactory.getResponseBean(StatusUtils.Success,service.saveStructureIntoNew(intoNew));
    }
    @RequestMapping("intoNew/get")
    @ResponseBody
    public ResponseBean getStructureIntoNew(Integer id){
        return ResponseFactory.getResponseBean(StatusUtils.Success,service.getStructureIntoNew(id));
    }
    @RequestMapping("intoNew/del")
    @ResponseBody
    public ResponseBean delStructureIntoNew(Integer id){
        service.delStructureIntoNew(id);
        return ResponseFactory.getResponseBean(StatusUtils.Success);
    }
    @RequestMapping("intoNew/find")
    @ResponseBody
    public ResponseBean findStructureIntoNew(Integer pageNum, Integer pageSize) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success,service.listStructureIntoNew(pageNum,pageSize));
    }
}
